package mobile.ui.cliente;

import mobile.dominio.Cliente;
import mobile.persistencia.PCliente;
import mobile.ui.LaAnfitriona;
import waba.fx.Color;
import waba.fx.Rect;
import waba.sys.Settings;
import waba.ui.Button;
import waba.ui.Control;
import waba.ui.ControlEvent;
import waba.ui.Event;
import waba.ui.MessageBox;
import waba.ui.TabPanel;
import waba.ui.Window;
import waba.util.Vector;

public class VerCliente extends Window{
	private Cliente unCliente;
	   
	private NuevoGeneral solapaGeneral;
	private NuevoEnvases solapaEnvase;
	private TabPanel tp;
	private Button btnCerrar;
	
	public VerCliente(Cliente esteCliente) {
		unCliente = esteCliente;
		solapaEnvase = new NuevoEnvases();
		solapaGeneral = new NuevoGeneral();
		Button.commonGap = 1;

		this.setBackColor(Color.getColor(255, 255, 225));
		tp = new TabPanel(new String[]{ "General", "Saldo Envases" });
		tp.setBorderStyle(Window.NO_BORDER); // no borders, please
		Rect r = getClientRect();
		tp.setBackColor(Color.BRIGHT);

		add(btnCerrar = new Button("       Cerrar       "), RIGHT - 2, BOTTOM - 2);

		r.height = btnCerrar.getPos().y-2; // don't let it get beyond the buttons
		r.x++; r.width-=2; // these adjusts make the cursor appear correctly on pen less
		tp.setRect(r);
		tp.setPanel(1, solapaEnvase);
		tp.setPanel(0, solapaGeneral);
		add( tp );

		if (Settings.isColor)
		{
			Color clrBack = LaAnfitriona.defaultBackColor;
			Color clrFore = LaAnfitriona.defaultForeColor;
			btnCerrar.setBackColor(clrBack);
			btnCerrar.setForeColor(clrFore);
		}
		// reassign the tab order
		tabOrder = new Vector(new Control[]{tp, btnCerrar});
		update();
	}


	public void update()
	{
		if (unCliente == null)
		{
			cleanEdit();
		}
		else
		{
			solapaGeneral.setEdit(unCliente);
			solapaEnvase.setEdit(unCliente);
		}
	}
	   
	/**
	 * Empty all edit boxes and set the active panel to the first one
	 */
	public void cleanEdit()
	{
		solapaGeneral.cleanEdit();
		solapaEnvase.cleanEdit();
		tp.setActiveTab(0);
	}
	
	public void onEvent(Event e){
		switch (e.type){
			case ControlEvent.PRESSED:
				if (e.target == btnCerrar){
					unpop();
				}
				break;
		}
	}

	public void onAdd()
	{
		update();
	}

}
